package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import com.stylefeng.guns.modular.system.service.ICustomerAddressService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.ConsumerCollection;
import com.stylefeng.guns.modular.system.service.IConsumerCollectionService;

import java.util.Date;

/**
 * 用户收藏表控制器
 *
 * @author fengshuonan
 * @Date 2019-09-09 21:57:04
 */
@Controller
@RequestMapping("/consumerCollection")
public class ConsumerCollectionController extends BaseController {

    private String PREFIX = "/system/consumerCollection/";

    @Autowired
    private IConsumerCollectionService consumerCollectionService;
    @Autowired
    private ICustomerAddressService customerAddressService;

    /**
     * 跳转到用户收藏表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "consumerCollection.html";
    }

    /**
     * 跳转到添加用户收藏表
     */
    @RequestMapping("/consumerCollection_add")
    public String consumerCollectionAdd() {
        return PREFIX + "consumerCollection_add.html";
    }

    /**
     * 跳转到修改用户收藏表
     */
    @RequestMapping("/consumerCollection_update/{consumerCollectionId}")
    public String consumerCollectionUpdate(@PathVariable Integer consumerCollectionId, Model model) {
        ConsumerCollection consumerCollection = consumerCollectionService.selectById(consumerCollectionId);
        model.addAttribute("item",consumerCollection);
        LogObjectHolder.me().set(consumerCollection);
        return PREFIX + "consumerCollection_edit.html";
    }

    /**
     * 获取用户收藏表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return consumerCollectionService.selectList(null);
    }

    /**
     * 新增用户收藏表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConsumerCollection consumerCollection) {
        consumerCollection.setCollectionTime(new Date());
        consumerCollectionService.insert(consumerCollection);
        return SUCCESS_TIP;
    }

    /**
     * 删除用户收藏表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer consumerCollectionId) {
        consumerCollectionService.deleteById(consumerCollectionId);
        return SUCCESS_TIP;
    }

    /**
     * 修改用户收藏表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConsumerCollection consumerCollection) {
        consumerCollectionService.updateById(consumerCollection);
        return SUCCESS_TIP;
    }

    /**
     * 用户收藏表详情
     */
    @RequestMapping(value = "/detail/{consumerCollectionId}")
    @ResponseBody
    public Object detail(@PathVariable("consumerCollectionId") Integer consumerCollectionId) {
        return consumerCollectionService.selectById(consumerCollectionId);
    }

    /**
     * @api {POST} /consumerCollection/search/{consumerId} 通过消费者id查询收藏列表
     * @apiName searchConsumerCollectionById
     * @apiGroup ConsumerCollection
     *
     * @apiParam {Number} consumerId 登录用户的id.
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *     "data": [
     *         {
     *             "base64": "",
     *             "companyId": 1,
     *             "createTime": "2019-09-11 23:59:32",
     *             "distincts": "3",
     *             "enabled": 1,
     *             "evaluation": 2.5,
     *             "id": 1,
     *             "idcard": "510122111819929577",
     *             "imgUrl": "430bcd42335704f7da0b58a8fe2de6e1",
     *             "introduction": " 狠可爱菲欧该金融二狗加热管日非叫我if和我我功夫和瑞风和日发货热 分我同房间诶我",
     *             "latitude": 30.6390936076,
     *             "longitude": 104.0501403809,
     *             "name": "小雯",
     *             "rank": "normal",
     *             "realName": "苍井空",
     *             "serviceArea": "武侯区",
     *             "sex": 1,
     *             "stat": "25",
     *             "state": 2,
     *             "tel": "15982276784",
     *             "updateTime": "2019-09-04 00:01:00",
     *             "viewProfessionalTitle": "6"
     *         }
     *     ],
     *     "msg": "SUCCESS",
     *     "status": "0000",
     *     "userType": ""
     * }
     */
    @RequestMapping(value = "/search/{consumerId}")
    @ResponseBody
    public ResponseResultDTO searchByConsumerId(@PathVariable("consumerId") Integer consumerId) {
        return consumerCollectionService.searchByConsumerId(consumerId);
    }


    /**
     * 查询是否收藏
     * @param consumerId
     * @param artificerId
     * @return
     */
    @RequestMapping(value = "/searchByConsumerIdArtificerId")
    @ResponseBody
    public ResponseResultDTO searchByConsumerIdArtificerId(Integer consumerId,Integer artificerId) {
        return consumerCollectionService.searchByConsumerIdArtificerId(consumerId,artificerId);
    }

    /**
     * 删除用户收藏表
     */
    @RequestMapping(value = "/deleteCollection")
    @ResponseBody
    public ResponseResultDTO  deleteCollection(Integer consumerId,Integer artificerId) {
        return consumerCollectionService.deleteCollection(consumerId,artificerId);
    }

    /**
     * 修改用户收藏表
     */
    @RequestMapping(value = "/isCollection")
    @ResponseBody
    public ResponseResultDTO isCollection(Integer artificerId,Integer customerId,Integer status) {
        return consumerCollectionService.isCollection(artificerId,customerId,status);
    }
}
